home *** CD-ROM | disk | FTP | other *** search
/ Reverse Code Engineering RCE CD +sandman 2000 / ReverseCodeEngineeringRceCdsandman2000.iso / RCE / Ebooks / Thinking in C++ V2 / C26 / readLower.h < prev    next >
Encoding:
C/C++ Source or Header  |  2000-05-25  |  939 b   |  39 lines

  1. //: C26:readLower.h
  2. // From Thinking in C++, 2nd Edition
  3. // Available at http://www.BruceEckel.com
  4. // (c) Bruce Eckel 1999
  5. // Copyright notice in Copyright.txt
  6. // Read a file into a container of string, 
  7. // forcing each line to lower case.
  8. #ifndef READLOWER_H
  9. #define READLOWER_H
  10. #include "../require.h"
  11. #include <iostream>
  12. #include <fstream>
  13. #include <string>
  14. #include <algorithm>
  15. #include <cctype>
  16.  
  17. inline char downcase(char c) {
  18.   using namespace std; // Compiler bug
  19.   return tolower(c);
  20. }
  21.  
  22. std::string lcase(std::string s) {
  23.   std::transform(s.begin(), s.end(),
  24.     s.begin(), downcase);
  25.   return s;
  26. }
  27.  
  28. template<class SContainer> 
  29. void readLower(char* filename, SContainer& c) {
  30.   std::ifstream in(filename);
  31.   assure(in, filename);
  32.   const int sz = 1024;
  33.   char buf[sz];
  34.   while(in.getline(buf, sz))
  35.     // Force to lowercase:
  36.     c.push_back(string(lcase(buf)));
  37. #endif // READLOWER_H ///:~
  38.